package android.front;

import android.app.Activity;
import android.graphics.ColorMatrixColorFilter;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
import android.widget.ImageButton;

public class Android_TranslateActivity extends Activity {
    /** Called when the activity is first created. */
	ImageButton imagebtn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imagebtn = (ImageButton)findViewById(R.id.imagebtn);
        imagebtn.setOnTouchListener(buttonOnTouchListener);
        imagebtn.setOnFocusChangeListener(buttonOnFocusChangeListener);
    }
    
    public final static float[] BT_SELECTED = new float[]
    		{
    			2,0,0,0,2,
    			0,2,0,0,2,
    			0,0,2,0,2,
    			0,0,0,1,0
    		};
    
    public final static float[] BT_NOT_SELECTED = new float[]
    		{
    			1,0,0,0,0,
    			0,1,0,0,0,
    			0,0,1,0,0,
    			0,0,0,1,0
    			
    		};
    
    public final static OnFocusChangeListener buttonOnFocusChangeListener = new OnFocusChangeListener()
    {

		public void onFocusChange(View v, boolean hasFocus) {
			// TODO Auto-generated method stub
			if(hasFocus)
			{
				v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
				v.setBackgroundDrawable(v.getBackground());
			}
			else
			{
				v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_NOT_SELECTED));
				v.setBackgroundDrawable(v.getBackground());
			}
		}
		
    };
    
    public final static OnTouchListener buttonOnTouchListener = new OnTouchListener()
    {

		public boolean onTouch(View v, MotionEvent event) {
			// TODO Auto-generated method stub
			if(event.getAction() == MotionEvent.ACTION_DOWN)
			{
				v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
				v.setBackgroundDrawable(v.getBackground());
			}
			else if(event.getAction() == MotionEvent.ACTION_UP)
			{
				v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_NOT_SELECTED));
				v.setBackgroundDrawable(v.getBackground());
			}
			return false;
		}
    	
    };
}